import { Orderitem } from './../../models/order';
import * as R from "ramda";

export namespace itemsProcess{
    interface Item{
        id:string;
        qty:number;
        refundQty?:number;
    }
    const splitItemsByItems = (items:Array<Item>)=>  {
        const newItems:Array<Item> = [];
        items&&items.forEach(item=>{
            if(!item.refundQty){
                newItems.push(item);
            } else {
                const refundItem = JSON.parse(JSON.stringify(item));
                refundItem.id += "refund";
                refundItem.qty = item.refundQty;
                refundItem.refundQty = item.refundQty;
                newItems.push(refundItem);
                item.qty = item.qty - item.refundQty;
                item.refundQty = 0;
                newItems.push(item);
            }
        })
        return newItems;
    }
    export const itemsPipe = R.pipe(splitItemsByItems);
}